<?php
require_once("rpcl/rpcl.inc.php");
require_once("config/data.php");
//Includes
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class modifysxxm extends Page
{
   public $ModComboBoxStuClass = null;
   public $LabelExpId = null;
   public $PanelModExp = null;
   public $LabelCourseName = null;
   public $LabelClassName = null;
   public $ButtonConfirmModify = null;
   public $LabelKeShi = null;
   public $ModEditKeShi = null;
   public $LabelExpName = null;
   public $ModEditExpName = null;
   //public $EditXuequ = null;
   public $ModComboBoxStuProf = null;
   public $LabelStuProfName = null;
   //public $EditClassName = null;
   public $ModComboBoxCourseName = null;
   public $ButtonCanelModify = null;
   public $HiddenfieldExpId = null;

   function modifysxxmCreate($sender, $params)
   {
      global $dzsxDB;
      if( ! isset($_SESSION['TeacherId']))
      {
         redirect("../index.php");
      }
      else
      {
         $v = $_SESSION['TeacherId'];
         if(isset($_GET['modifyId']))
         {
            $modifyId = $_GET['modifyId'];
            $this->HiddenfieldExpId->Value = $modifyId;
            $dzsxDB->QueryModifyExpinfo->Active = False;
            $dzsxDB->QueryModifyExpinfo->SQL = "Select * from expinfo where TeacherId='$v' And ExpId=$modifyId";
            $dzsxDB->QueryModifyExpinfo->Active = True;
         }
      }
      $this->LabelExpId->caption = "项目编号：" . $dzsxDB->QueryModifyExpinfo->ExpId;
      $this->ModEditExpName->text = $dzsxDB->QueryModifyExpinfo->ExpName;
      $this->ModEditKeShi->text = $dzsxDB->QueryModifyExpinfo->keshi;
   }

   /*------在课程添加选择列表框中添加课程--------*/
   function ModComboBoxCourseNameBeforeShow($sender, $params)
   {
      global $dzsxDB;
      $this->ModComboBoxCourseName->clear();//防止重复添加选项，每次刷新时先清空
      $dzsxDB->QueryTeacherCourse->Active = false;
      $dzsxDB->QueryTeacherCourse->SQL = "Select * from course order by CourseName ";
      $dzsxDB->QueryTeacherCourse->Active = true;
      $dzsxDB->QueryTeacherCourse->first();
      while( ! $dzsxDB->QueryTeacherCourse->EOF)
      {
         $this->ModComboBoxCourseName->AddItem($dzsxDB->QueryTeacherCourse->CourseName, null, $dzsxDB->QueryTeacherCourse->CourseId);
         $dzsxDB->QueryTeacherCourse->next();
      }
      $this->ModComboBoxCourseName->ItemIndex = $dzsxDB->QueryModifyExpinfo->CourseId;
   }

   /*------在专业添加选择列表框中添加专业--------*/
   function ModComboBoxStuProfBeforeShow($sender, $params)
   {
      global $dzsxDB;
      $this->ModComboBoxStuProf->clear();
      $dzsxDB->QueryStuProf->Active = False;
      $dzsxDB->QueryStuProf->SQL = "Select * From prof order by ProfId ";
      $dzsxDB->QueryStuProf->Active = True;
      $dzsxDB->QueryStuProf->first();
      while( ! $dzsxDB->QueryStuProf->EOF)
      {
         $this->ModComboBoxStuProf->AddItem($dzsxDB->QueryStuProf->ProfName, null, $dzsxDB->QueryStuProf->ProfId);
         $dzsxDB->QueryStuProf->next();
      }
      $this->ModComboBoxStuProf->ItemIndex = $dzsxDB->QueryModifyExpinfo->ProfId;
      $this->SelcetClassByProf($sender, $dzsxDB->QueryModifyExpinfo->ProfId);
   }

   function ModComboBoxStuClassBeforeShow($sender, $params)
   {
      global $dzsxDB;

   }


   /*------根据专业选择班级--------*/
   function ModComboBoxStuProfJSChange($sender, $params)
   {
      ?>
        //begin js
        params=$("#ModComboBoxStuProf").val();
        $("#ButtonConfirmModify").attr("disabled", true);
        //end
      <?php
      echo $this->ModComboBoxStuProf->ajaxcall("SelectClass", array(), array('ModComboBoxStuClass'));
   }

   function SelectClass($sender, $params)
   {
      global $dzsxDB;
      $this->ModComboBoxStuClass->clear();
      $this->SelcetClassByProf($sender, $params);
      global $ajaxResponse;
   }

   function SelcetClassByProf($sender, $params)//根据专业选择班级，并添加到ComboBoxStuClass中
   {
      global $dzsxDB;
      $this->ModComboBoxStuClass->clear();
      $StuProfId = $params;
      $dzsxDB->QueryStuClass->Active = False;
      $dzsxDB->QueryStuClass->SQL = "Select ClassName From student Where ProfId='$StuProfId' Group By ClassName";
      $dzsxDB->QueryStuClass->Active = True;
      $dzsxDB->QueryStuClass->first();
      while( ! $dzsxDB->QueryStuClass->EOF)
      {
         $this->ModComboBoxStuClass->AddItem($dzsxDB->QueryStuClass->ClassName);
         $dzsxDB->QueryStuClass->next();
      }
   }

   /*----确认修改-------*/
   function ButtonConfirmModifyClick($sender, $params)
   {
      global $dzsxDB;
      $v = $_SESSION['TeacherId'];
      $modifyId = $this->HiddenfieldExpId->Value;
      $Mod_CourseId = $this->ModComboBoxCourseName->ItemIndex;//$this->ComboBoxCourseName->Items[$this->ComboBoxCourseName->ItemIndex];
      $Mod_StuProf = $this->ModComboBoxStuProf->ItemIndex;
      $Mod_StuClass = $this->ModComboBoxStuClass->Items[$this->ModComboBoxStuClass->ItemIndex];
      //$Mod_Xuequ = $this->EditXuequ->text;
      $Mod_ExpName = $this->ModEditExpName->text;
      $Mod_Keshi = $this->ModEditKeShi->text;
      $dzsxDB->QueryModifyExpinfo->Active = False;
      $dzsxDB->QueryModifyExpinfo->SQL = "UPDATE expinfo SET ExpName='$Mod_ExpName',
      CourseId='$Mod_CourseId',ProfId='$Mod_StuProf',ClassName='$Mod_StuClass',
      keshi='$Mod_Keshi' WHERE ExpId=$modifyId ";
      $dzsxDB->QueryModifyExpinfo->Active = True;

      /*----下面语句清除已经填写完的内容,解决刷新重复添加问题-------*/
      $this->HiddenfieldExpId->Value = "";
      $dzsxDB->QueryModifyExpinfo->Active = False;
      $this->ModComboBoxCourseName->clear();
      $this->ModComboBoxStuProf->clear();
      //$this->EditClassName->text = "";
      //$this->EditXuequ->text = "";
      $this->ModEditExpName->text = "";
      $this->ModEditKeShi->text = "";
      $dzsxDB->QueryModifyExpinfo->SQL = "";
      redirect("teacher.php");
   }

   /*----取消修改-------*/
   function ButtonCanelModifyClick($sender, $params)
   {
      $this->HiddenfieldExpId->Value = "";
      $dzsxDB->QueryModifyExpinfo->Active = False;
      $this->ModComboBoxCourseName->clear();
      $this->ModComboBoxStuProf->clear();
      // $this->EditClassName->text = "";
      //$this->EditXuequ->text = "";
      $this->ModEditExpName->text = "";
      $this->ModEditKeShi->text = "";
      $dzsxDB->QueryModifyExpinfo->SQL = "";
      redirect("teacher.php");
   }

   function modifysxxmAfterAjaxProcess($sender, $params)
   {
      global $ajaxResponse;
      $ajaxResponse->script("$('#ButtonConfirmModify').removeAttr('disabled');");
   }


}

global $application;

global $modifysxxm;

//Creates the form
$modifysxxm = new modifysxxm($application);

//Read from resource file
$modifysxxm->loadResource(__FILE__);

//Shows the form
$modifysxxm->show();

?>